package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.model.MyResponseData;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("user/")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("login")
    public MyResponseData userlogin(String username , String password) {
        MyResponseData responseData = new MyResponseData();
        User user = userService.selectUser(username,password);
        if (user == null) {
            responseData.setErrorCode(1);
            responseData.setMsg("登录失败");

        } else {
            responseData.setErrorCode(0);
            responseData.setMsg("登录成功");
            responseData.setObject(user);
        }
        return responseData;
    }
}
